<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.appspot.niehonglei.jdo.Common" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.appspot.niehonglei.dao.PMF" %>
<%@ page import="com.appspot.niehonglei.common.Tools" %>
<%
	/**
	 * 
	 */


	if(!"niehonglei".equals(session.getAttribute("logName"))){
		response.sendRedirect("/");
		return;
	}
	if(request.getParameter("new")!=null){
		session.removeAttribute("editCommon");
	}
	String type = request.getParameter("type");
	if(!"0".equals(type) && !"1".equals(type)){
		type = "0";
	}
	/**
	 * 
	 */	
	Common editCommon = (Common)session.getAttribute("editCommon");
	String title = "";
	String link = "";
	String id = "";
	if(editCommon!=null){

		title = editCommon.getTitle();
		link = editCommon.getLink();
		type = editCommon.getType() + "";
		if(editCommon.getId()!=null){
			id = editCommon.getId().intValue() + "";
		}
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>编辑链接</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-size: 12px;
	line-height: 20px;
}
.sideTitle {
	font-size: 14px;
	font-weight: bold;
	color: #E25209;
}
.basicInfo {
	color: #999;
}
.whiteText {
	color: #FFF;
}
.blackText {
	color: #000;
}
.title {
	font-size: 18px;
	font-weight: bold;
	color: #E25209;
}

a.whiteText{

}
a{
	text-decoration:none;
}
a:hover{
	text-decoration:underline;
}

-->
</style>
</head>

<body>
<font color="#FF0000" style="display:none" id="tip"></font>
<form id="myForm" name="myForm" action="/action/saveCommon" method="post">
  <p> 
  <input type="button" name="publisharticle" id="publisharticle" onclick="location.href='/publish?new'" value="发布文章" />
  <input type="button" name="indexrecommend" id="indexrecommend" onclick="location.href='/common?new&type=0'" <%if("0".equals(type)) out.print("disabled='disabled'");%> value="首页推荐" />
  <input type="button" name="friendlinks"  id="friendlinks" onclick="location.href='/common?new&type=1'" <%if("1".equals(type)) out.print("disabled='disabled'");%> value="友情链接" />
  <input type="button" name="publisharticle" id="publisharticle" onclick="location.href='/comment'" value="管理评论" />
    <br />
     标题：<input name="title" type="text" id="title" value="<%= Tools.dealNull(title)%>" size="80"/>
	  <br />
	 链接：<input name="link" type="text" id="link" value="<%= Tools.dealNull(link)%>" size="80"/>
<br />
	<input name="type" id="type" type="hidden" value="<%= Tools.dealNull(type)%>" />
	<input name="id" type="hidden" id="id" value="<%= Tools.dealNull(id)%>" />
	<br />
   
      <input type="submit" name="button" id="button" value="提交" /><input type="button" name="new"  id="new" onclick="location.href='/common?new&type=<%= type %>'" value="新建" /><input type="button" name="button1" value="首页" onclick="location.href='/'"/><input type="button" name="button22" onclick="location.href='/logout'" value="登出" />
    <br />
  </p>
</form>
  <%
  		PersistenceManager pm = PMF.get().getPersistenceManager();
		String query = "select from " + Common.class.getName() + " where type==" + type + " order by createDate desc";
		List<Common> list = (List<Common>) pm.newQuery(query).execute();
		if(list == null) return;
		for(int i=0;i<list.size();i++){
			Common common = list.get(i);
			out.println("<br>" + common.getId().intValue() + "：" + common.getTitle() + "（创建时间：" + Tools.date2str(common.getCreateDate()) + "，更新时间：" + Tools.date2str(common.getChangeDate()) + "）<input onclick='javascript:location.href=\"/action/deleteCommon&id="+common.getId().intValue()+"\";' type='button' value='删除'/>" + "<input onclick='javascript:location.href=\"/action/editCommon&id="+common.getId().intValue()+"\";' type='button' value='编辑'/><p>" + common.getLink() + "</p>");
		}
		pm.close();
  %>
</body>
</html>
